from celery.app.control import Control
from config.celery import app

def monitor_tasks():
    """监控任务队列状态"""
    control = Control(app=app)
    
    print("\n=== 活跃任务 ===")
    active = control.inspect().active()
    if active:
        for worker, tasks in active.items():
            print(f"\n{worker}:")
            for task in tasks:
                print(f"- {task['name']}: {task['id']}")
    
    print("\n=== 预定任务 ===")
    scheduled = control.inspect().scheduled()
    if scheduled:
        for worker, tasks in scheduled.items():
            print(f"\n{worker}:")
            for task in tasks:
                print(f"- {task['name']}: {task['id']}")
    
    print("\n=== 保留任务 ===")
    reserved = control.inspect().reserved()
    if reserved:
        for worker, tasks in reserved.items():
            print(f"\n{worker}:")
            for task in tasks:
                print(f"- {task['name']}: {task['id']}")
    
    print("\n=== 注册队列 ===")
    active_queues = control.inspect().active_queues()
    if active_queues:
        for worker, queues in active_queues.items():
            print(f"\n{worker}:")
            for queue in queues:
                print(f"- {queue['name']}")

if __name__ == "__main__":
    monitor_tasks() 